package controller;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;

import view.AdminContactView;
import view.AdminView;
import view.Menu;

public class ActionAdmin implements ActionListener {

	@Override
	public void actionPerformed(ActionEvent e) {
		String name = ((JComponent) e.getSource()).getName();
		System.out.println("menu");
		switch (name) {
		case "utnDb": {// invia alert ad un utente
			Engine.pauseHome();
			if (Menu.flagAlert)
				AdminContactView.restart(true);
			else{
				new AdminContactView(true);
				Menu.flagAlert = true;
			}
			break;
		}
		case "evnDb": {// visualizza eventi di un utente
			Engine.pauseMenu();
			if (Menu.flagEvent)
				AdminContactView.restart(false);
			else{
				new AdminContactView(false);
				Menu.flagEvent = true;
			}

			break;
		}
		case "utnSt": {
			Engine.pauseHome();
			new AdminView("utnSt"); // visualizza statistiche su settori utenti
			break;
		}
		case "evnSt": {
			Engine.pauseHome();
			new AdminView("evnSt"); // visualizza statistiche su tipologie
			// eventi
			break;
		}
		case "viewEventContact": {
			JButton j = new JButton();
			Color colore = j.getBackground();
			if (((JComponent) e.getSource()).getBackground() != Color.green) {
				((JComponent) e.getSource()).setBackground(Color.green);
				AdminContactView.selectContact.add(Integer.valueOf(((JComponent) e.getSource()).getComponent(0).getName()));
			}
			else {
				for (int i = 0; i < AdminContactView.selectContact.size(); i++)
					//System.out.println(AdminContactView.selectContact.get(i));
					if (Integer.valueOf(((JComponent) e.getSource())
							.getComponent(0).getName()) == AdminContactView.selectContact.get(i)) {
						AdminContactView.selectContact.remove(i);
						break;
					}
				((JComponent) e.getSource()).setBackground(colore);
			}
			HomeCalendarObserver.obs.uppdater();
			break;
		}

		case "alertContact": {
			AdminContactView.alertMessage(Integer.valueOf(((JButton) e.getSource()).getComponent(0).getName()));
			break;
		}
		}

	}

}
